/* 
 * GuiHelper.java 23.10.2011
 *  
 *  
 * Candidate: Alessandra Otterbach
 * Prometric ID: Algisina1
 * Username: Algisina
 *  
 * Sun Certified Developer for Java 2 Platform, Standard Edition Programming 
 * Assignment (CX-310-252A)
 *  
 * This class is part of the Programming Assignment of the Sun Certified 
 * Developer for Java 2 Platform, Standard Edition certification program, must 
 * not be used out of this context and must be used exclusively by Sun 
 * Microsystems, Inc. 
 */
package suncertify.ps;

import java.rmi.registry.Registry;
import java.util.Properties;

import suncertify.util.PropertiesHelper;
import suncertify.util.StringUtils;

/**
 * Helper class for getting properties out of the property-file.
 * 
 * @author Alessandra Otterbach
 * 
 */
public class GuiHelper {

    /**
     * Reads the path out of the properties, if there is one.
     * 
     * @return property path or empty String, if there is no path in the file.
     */
    public static String getPropertyPath() {
	Properties properties = PropertiesHelper.readProperties();

	if (!properties.isEmpty()) {
	    return properties.getProperty(PropertiesHelper.PROP_PATH);
	}

	return "";
    }

    /**
     * Reads the ip out of the properties, if there is one.
     * 
     * @return property ip or empty String, if there is no ip in the file.
     */
    public static String getPropertyIp() {
	Properties properties = PropertiesHelper.readProperties();

	if (!properties.isEmpty()
		&& StringUtils.isNotEmpty(properties
			.getProperty(PropertiesHelper.PROP_IP))) {
	    return properties.getProperty(PropertiesHelper.PROP_IP);
	}

	return "";
    }

    /**
     * Reads the port number out of the properties, if there is one.
     * 
     * @return property port number or standard registry port, if there is no
     *         port number in the file.
     */
    public static String getPropertyPort() {
	Properties properties = PropertiesHelper.readProperties();

	if (!properties.isEmpty()
		&& StringUtils.isNotEmpty(properties
			.getProperty(PropertiesHelper.PROP_PORT))) {
	    return properties.getProperty(PropertiesHelper.PROP_PORT);
	} else {

	    return String.valueOf(Registry.REGISTRY_PORT);
	}
    }
}
